#pragma once

#include <stack>

#include "Singleton.h"
#include "WinMutex.h"
#include "WinThread.h"
#include "LoaderConfig.h"
#include <SFML\Network.hpp>
#include "Packet.h"
#include "GameState.h"
#include "Client.h"

class DataBase : public Singleton<DataBase>
{
	friend class Singleton<DataBase>;

private:
	DataBase(void);
	~DataBase(void);

	std::vector<Client*>			m_clients;
	WinMutex						m_mutexClients;

	std::vector<SPacket*>			m_stackRecv;
	WinMutex						m_mutexStackRecv;

	std::vector<SPacket*>			m_stackSend;
	WinMutex						m_mutexStackSend;
	
public:
	void							initDatabase();

	//CLIENTS
	void							pushBackClient(Client*);
	void							eraseClientAt(int);
	int								getSizeClients();
	Client*							getElementAt(int);
		
	//STACK RECV
	void							pushStackRecv(SPacket*);
	SPacket*						popStackRecv();
	int								getSizeStackRecv();

	//STACK SEND
	void							pushStackSend(SPacket*);
	SPacket*						popStackSend();
	int								getSizeStackSend();

	//STATE
	GameState						getCurrentState();
	void							setState(GameState);

	sf::TcpListener					m_listener;
	sf::SocketSelector				m_selector;

	WinThread						m_gameLoop;
	//stackSend

	GameState						m_state;
	WinMutex						m_mutexState;

	bool			m_alive;
	int				m_fps;
	int				m_port;
	int				m_maxPlayers;
	bool			m_typeGenerate;
};